app.controller("batchController",function ($scope,$controller,batchService,$location, taxInfoService) {

    $controller('baseController',{$scope:$scope});

    //定义搜索对象
    $scope.searchEntity = {};

    //获取打款记录
    $scope.findPage = function (pageNum, pageSize) {

        if (pageNum == null) pageNum = 1;

        if (pageSize == null) pageSize = 10;

        if (startTime != null) $scope.searchEntity.startTime = startTime;

        if (endTime != null) $scope.searchEntity.endTime = endTime;

        //获取地址栏批次号
        var batchNumber = $location.search()['batchNumber'];

        if (batchNumber != null) {
            $scope.searchEntity.batchNo = batchNumber;
        }
        $scope.findTaxInfoByBrandId()

        batchService.findPage(pageNum,pageSize,$scope.searchEntity).success(function (response) {

            if (response.code == 200){

                //获取打款记录
                $scope.batchList = response.data;

                //更新总记录数
                $scope.paginationConf.totalItems=response.total;

            } else {
                alert(response.msg)
            }
        })

    };

    //重置条件查询参数
    $scope.resetSearchEntity = function(){

        $scope.searchEntity = {};

        $scope.reloadList();
    };


    //监控 批次状态 status 变量
    $scope.$watch("searchEntity.status",function(newValue,oldValue){
        if (newValue == null)return;

        $scope.reloadList();

    });

    //监控 是否开票 isInvoice 变量
    $scope.$watch("searchEntity.isInvoice",function (newValue, oldValue) {

        if (newValue == null) return;

        $scope.reloadList();

    });

    //重置条件查询参数
    // $scope.reset = function () {
    //
    //     alert(111);
    //     $scope.serachEntity = {};
    //
    //     $scope.reloadList();
    //
    // };


    //批次明细下载
    $scope.download = function (batchNo,companyName) {

        if (!confirm("您确定导出吗？"))  return;

        $scope.downloadParam = {"batchNumber":batchNo,"companyName":companyName};

        console.log($scope.downloadParam);

        batchService.download($scope.downloadParam).success(function (response) {

            if (response.code == 200){

                // 文件下载
                window.open(response.msg);

            }else {

                alert(response.msg);

            }
        })

    }


    $scope.taxInfoList = []
    $scope.findTaxInfoByBrandId = function () {
        taxInfoService.findByBrandId().success(function (res) {
            $scope.taxInfoList = res.data;
        });
    };
});